﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//------------//
using QLKTX1._0.DTO;
using QLKTX1._0.DB;
using System.Data.SqlClient;
using System.Data;
//....................
namespace QLKTX1._0.DAO
{
    class PhongODAO
    {
       public static  List<PhongODTO> dsPhongO()
        {
            List<PhongODTO> dsPhong = new List<PhongODTO>();

            ConnectDB con = new ConnectDB();
            DataTable dt = con.getDataTable("SELECT * FROM PhongO");

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                PhongODTO po = new PhongODTO();

                PhongDTO p = new PhongDTO();
                p.MaPhong = dt.Rows[i]["maPhong"].ToString();

                HienTrangPhongDTO htp = new HienTrangPhongDTO();
                htp.MaHienTrang = Int32.Parse (dt.Rows[i]["maHienTrang"].ToString());

                LoaiPhongDTO lp = new LoaiPhongDTO();
                lp.MaLoaiPhong = dt.Rows[i]["maLoaiPhong"].ToString();

                DotDangKyDTO ddk = new DotDangKyDTO();
                ddk.MaDot = dt.Rows[i]["maDot"].ToString();

                po.MaPhongO = Int32.Parse (dt.Rows[i]["maPhong"].ToString());
                po.MaPhong = p;
                po.MaHienTrang = htp;
                po.MaLoaiPhong = lp;
                po.MaDot = ddk;


                dsPhong.Add(po);
            }

            return dsPhong;
        }
       //Ham Insert
       public static bool themPhongO(PhongODTO p)
       {
           ConnectDB con = new ConnectDB();// dung DB

           return con.executeQuery("INSERT INTO PhongO(maPhong,maHienTrang,maLoaiPhong,maDot,SL_DangKy,SL_Con,tinhTrang) VALUES('" + p.MaPhong .MaPhong  + "','" + p.MaHienTrang .MaHienTrang  + "','" + p.MaLoaiPhong.MaLoaiPhong + "','" + p.MaDot.MaDot + "',"+p.SoLuongDangKy +","+p.SoLuongCon +","+p.TinhTrang+ ")");
       }
       //Ham Delete
       public static bool xoaPhongO(PhongODTO p)
       {
           ConnectDB con = new ConnectDB();

           return con.executeQuery("DELETE FROM PhongO WHERE maPhongO='" + p.MaPhongO + "' ");
       }
       //Ham Update
       public static bool capNhatPhongO(PhongODTO p)
       {
           ConnectDB con = new ConnectDB();

           return con.executeQuery("UPDATE PhongO set SL_DangKy=" + p.SoLuongDangKy + ",SL_Con=" + p.SoLuongCon + ",tinhTrang=" + p.TinhTrang + "  WHERE maPhongO='" + p.MaPhongO + "'");
       }
    }
}
